<script>
export default {
  data() {
    return {
      show: false,
      item: {
        // 分组编码
        groupCode: '',
        // 编码
        code: "",
        // 标题
        title: '',
      },
      groupData: [],

      loading: false
    }
  },
  created() {
    this.getGroupData();
  },
  methods: {
    /**
     * 获取分组数据
     */
    getGroupData() {
      this.$kt.requestSecurity.send({
        uri: "/functional-template-web/admin/functionalTemplateGroup/getList",
        stateSuccess: (res) => {
          this.groupData = [{
            code: "",
            name: "全部"
          }];
          let resData = res.data;
          for (let i = 0; i < resData.length; i++) {
            this.groupData.push(resData[i]);
          }

        },
        stateFail: (err) => {
          this.$message.error(err.errMsg);
        }
      });
    },
    open(row) {
      this.item = this.$kt.util.deepCopy(row);
      this.show = true;
      // 获取分组数据
      this.getGroupData();
    },
    /**
     * 保存
     */
    toSave() {
      this.loading = true;
      this.$kt.requestSecurity.send({
        uri: "/functional-template-web/admin/functionalTemplate/save",
        data: this.item,
        stateSuccess: (res) => {
          this.show = false;
          this.$emit('submit');
          this.loading = false;
        },
        stateFail: (err) => {
          this.$message.error(err.errMsg);
          this.loading = false;
        }
      });
    }
  }
}
</script>

<template>
  <el-dialog
      v-loading="loading"
      title="新增/修改"
      v-model="show">
    <el-form label-position="top">
      <el-form-item label="分组">
        <el-select v-model="item.groupCode" placeholder="请选择">
          <el-option
              v-for="item1 in groupData"
              :key="item1.code"
              :label="`${item1.name} #${item1.code}`"
              :value="item1.code">
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="标题">
        <el-input v-model="item.title"></el-input>
      </el-form-item>
      <el-form-item label="编码">
        <el-input v-model="item.code"></el-input>
      </el-form-item>
      <el-form-item label="内容">
        <textarea v-model="item.content"
                  class="content-textarea"
        ></textarea>
      </el-form-item>
      <el-form-item>

      </el-form-item>

    </el-form>
    <div style="text-align: right">
      <el-button
          @click="toSave"
          type="primary">保存
      </el-button>
    </div>
  </el-dialog>

</template>

<style scoped lang="scss">
.content-textarea {
  width: 100%;
  height: 200px;
}
</style>